package cc.wanforme.chipmunity.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;

/**
 * @author wanne
 * 2019年7月16日
 * 默认数据源配置、主数据源配置
 */
@Configuration
public class DefaultDatabaseConfiguration {
	
	@Primary
	@Bean(name = "defaultDb")
	@ConfigurationProperties("spring.datasource.druid.default")
	public DataSource dataSource() {
		return DruidDataSourceBuilder.create().build();
	}
	
	@Primary
	@Bean(name = "defaultTransactionManager")
	public DataSourceTransactionManager defaultTransactionManager(@Qualifier("defaultDb") DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}
	
	
}
